function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

var BaseURL = {
  http: 'http://api.zuihuiyou.cn/',
  https: 'https://api.zuihuiyou.cn/',
  http_cc: 'http://api.zuihuiyou.cc/'
};

var Login = {
  avatar: '',
  realName: '',
  yxInfo: {},
  regionIdx: 0,
  livePlace: ['', '', ''],
  tags: [],
  briefComment: '',
  intro: '',
  description: '',
  authInfo: {},
  cityLifeInfo: '',
  serviceInfo: '',
  tripInfo: '',
  imgs: [],
  tagStates: [],
  isAvatarSaved: false,
  setAvatar: function(value) {
    this.avatar = value;
  },
  getAvatar: function() {
    return this.avatar;
  },
  setRealName: function (value) {
    this.realName = value;
  },
  getRealName: function () {
    return this.realName;
  },
  setYxInfo: function(value) {
    this.yxInfo = value;
  },
  getYxInfo: function() {
    return this.yxInfo || {};
  },
  setLiveCountry: function(value) {
    this.livePlace[0] = value;
  },
  setLiveCity: function(value) {
    this.livePlace[1] = value;
  },
  setLiveDuration: function(value) {
    this.livePlace[2] = value;
  },
  getLivePlace: function() {
    return this.livePlace;
  },
  setRegionIdx: function(value) {
    this.regionIdx = value;
  },
  getRegionIdx: function() {
    return this.regionIdx;
  },
  setTags: function(value) {
    this.tags = value;
  },
  getTags: function() {
    return this.tags;
  },
  setTagStates: function(value) {
    this.tagStates =value;
  },
  getTagStates: function() {
    return this.tagStates;
  },
  setBriefComment: function(value) {
    this.briefComment = value;
  },
  getBriefComment: function() {
    return this.briefComment;
  },
  setIntro: function(value) {
    this.intro = value;
  },
  getIntro: function() {
    return this.intro;
  },
  getDescription: function(value) {
    this.description = value;
  },
  setDescription: function() {
    return this.description;
  },
  setAuthInfo: function(value) {
    this.authInfo = value;
  },
  getAuthInfo: function() {
    return this.authInfo;
  },
  setCityLifeInfo: function(value) {
    this.cityLifeInfo = value;
  },
  getCityLifeInfo: function() {
    return this.cityLifeInfo;
  },
  setServiceInfo: function(value) {
    this.serviceInfo = value;
  },
  getServiceInfo: function() {
    return this.serviceInfo;
  },
  setTripInfo: function(value) {
    this.tripInfo = value;
  },
  getTripInfo: function() {
    return this.tripInfo;
  },
  setImgs: function (value) {
    this.imgs = value;
    /*try {
      wx.setStorageSync('imgs', JSON.stringify(value));
    } catch(e) {
      console.log(e.toString());
    }*/
  },
  getImgs: function() {
    return this.imgs;
    /*let that = this;
    try {
      var value = wx.getStorageSync('imgs');
      return value || [];
    }catch(e) {
      return [];
    }*/
    
  },
  setIsAvatarSaved: function(value) {
    this.isAvatarSaved = value;
  },
  getIsAvatarSaved: function() {
    return this.isAvatarSaved;
  },
  resetAll: function() {
    this.yxInfo = { };
    this.regionIdx = 0;
      this.livePlace = ['', '', ''];
        this.tags = [];
          this.briefComment = '';
            this.intro = '';
              this.description = '';
                this.authInfo = { };
                this.cityLifeInfo = '';
                  this.serviceInfo = '';
                    this.tripInfo = '';
                      this.imgs = [];
                        this.tagStates = [];
    wx.removeStorage({
      key: 'imgs',
      success: function(res) {},
    });                    
  },
  cacheAll: function() {
    let that = this;
  }
};

module.exports = {
  formatTime: formatTime,
  BaseURL: BaseURL,
  Login: Login
}
